package cn.kgc.util;


import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class StringTODateConver implements Converter<String, Date> {
    //用于保存日期格式
    private List<String> patterns;
    public void setPatterns(List<String> patterns) {
        this.patterns = patterns;
    }

    @Override
    public Date convert(String s) {
        Date date=null;
        for(String pattern:patterns){
            try {
                date=new SimpleDateFormat(pattern).parse(s);
                break;
            } catch (ParseException e) {
                continue;
            }
        }

        return date;
    }

    /*@Override
    public Integer convert(String s) {
        Integer i=Integer.parseInt(s);
        return i;
    }*/
}
